#Include "message.bas"
#include "sock.bi"

Function BotMain Alias "BotMain" ( rawmsg As String ) As message Export

   Dim as message n

   Dim as IRC.message myMessage

   static didonce as ubyte
   static numofinsults as uinteger
   static insults(1023) as string


   if didonce=0 then

      randomize timer,3

      dim as uinteger freef 
      freef=freefile

      open "insult.txt" for input as freef

      while not eof(freef)
	 numofinsults += 1
         line input #freef, insults (numofinsults)
      wend

      close freef
      didonce=1
   
   endif

   myMessage.parse( rawmsg )

   dim as string temp=myMessage.param (myMessage.trailing)

   if left(temp , len("^insult")) = "^insult" then

        n.dest = myMessage.param(0)
        n.msg = (right (temp, len(temp)-8)) & ": " & insults(int(rnd * numofinsults + 1))
        n.msgtype=1

   endif

   return n

end function
